package com.ddf.dao.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.ddf.dao.UserDao;
import com.ddf.entity.User;

@Repository
public class UserDaoImpl implements UserDao {
	private static Map<Integer, User> userMap;
	private static Integer id = 0;
	static {	
		userMap = new HashMap<Integer, User>();
		userMap.put(++id, new User(id, "ddf01", "12345601", "nan", "ddf01@123.com"));
		userMap.put(++id, new User(id, "ddf02", "12345602", "nan", "ddf02@123.com"));
		userMap.put(++id, new User(id, "ddf03", "12345603", "nan", "ddf03@123.com"));
		userMap.put(++id, new User(id, "ddf04", "12345604", "nan", "ddf04@123.com"));
	}
	@Override
	public Collection<User> getAllUser() {
		return userMap.values();
	}

	@Override
	public void addUser(User user) {
		user.setId(++id);
		userMap.put(id, user);
	}

	@Override
	public void updateUser(User user) {
		if(user.getId() != null) {
			userMap.put(user.getId(), user);
		}
	}

	@Override
	public void deleteUser(Integer id) {
		userMap.remove(id);
	}

	@Override
	public User getUserById(Integer id) {
		User user = new User();
		if(id != null) {
			user = userMap.get(id);
		}
		return user;
	}
	
}
